layui.config({
    base: '/static/layui/'
}).extend({
    index: 'index',
    formSelects: 'formSelects-v4'
}).use(['layer','form','formSelects'], function () {
    var $ = layui.$, form = layui.form,formSelects = layui.formSelects;;
    formSelects.btns('roleId',[]);
    form.verify({
        username: function(value){
            if(value.length < 4){
                return '标题至少得4个字符啊';
            }
        }
        ,password: [/(.+){6,18}$/, '密码必须6到12位']
    });
    form.on('switch(c-status)',function (data) {
        let checked = data.elem.checked;
        let v;
        checked == true? v=1:v=0;
        $('#status').val(v);
    });
    saveForm(form, "formBtn", "/sys/user/save");
    var id = $("#id").val();
    if (id != '' && id != null) {
        getData("/sys/user/get/"+ id, function (d) {
            form.val("baseForm", d.data);
            form.val("baseForm", {
                "c-status": d.data.status==1?true:false
            });
            formSelects.value('roleId', d.roleId);
        });
    };

});